package com.swpu.project.controller;


import com.swpu.project.common.BaseResponse;
import com.swpu.project.model.dto.data.DataEntityDto;
import com.swpu.project.model.entity.LoginUser;
import com.swpu.project.model.entity.Secondary;
import com.swpu.project.model.page.PageQuery;
import com.swpu.project.service.ISecondaryService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author swpuyanxiegroup1
 * @since 2024-07-29
 */
@RestController
@RequestMapping("/secondary")
public class SecondaryController {
  @Resource
  ISecondaryService iSecondaryService;



    @PreAuthorize("@verf.hasAnyAuthority('sys_add')")
    @PostMapping("/add")
    BaseResponse addSec(@RequestBody DataEntityDto dataEntityDto)
    {


        LoginUser principal = (LoginUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();

        return    iSecondaryService.addData(dataEntityDto);


    }

    @PutMapping("/update")
    @PreAuthorize("@verf.hasAnyAuthority('sys_update')")
    BaseResponse updateSec(@RequestBody Secondary secondary)
    {

        return iSecondaryService.updateData(secondary);

    }

    @GetMapping("/query")
    @PreAuthorize("@verf.hasAnyAuthority('sys_query')")
    BaseResponse querySec()
    {

        return iSecondaryService.querySecondary();
    }


  @GetMapping("/pagequery")
  @PreAuthorize("@verf.hasAnyAuthority('sys_query')")
  BaseResponse pageQueryNative(@RequestBody PageQuery pageQuery)
  {
    return iSecondaryService.pageQuery(pageQuery);
  }





}
